<!--
 * @Author: [kangjie]
 * @Date: 2022-04-29 09:56:25
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-04-29 10:07:59
 * @Description: :
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绘制圆</title>
  <script>
    window.onload=function(){
      // 1.获取画布
      var canvas=document.querySelector('canvas');
      // 2.获取画布上下文对象 获取画笔
      var context=canvas.getContext('2d');
      var bubble={
        x:100,
        y:100,
        r:50,
        color:'red'
      };
      draw(bubble);
      move(bubble);
      setInterval(()=>{
        // 清除画布
        context.clearRect(0,0,400,400)
        move(bubble)
      },200)
      // 绘制圆的方法
      function draw(bubble){
        context.beginPath();
        context.arc(bubble.x,bubble.y,bubble.r,0,Math.PI *2 );
        context.closePath();
        context.fillStyle='blue';
        context.fill()
      }
      // 移动
      function move(bubble){
        bubble.x+=5;
        bubble.y+=5;
        draw(bubble);
      }
    }
  </script>
</head>
<body>
  <canvas width="400px" height="400px"></canvas>
</body>
</html>